from celery import Celery
from app.config import Config

def make_celery(name=__name__):
    return Celery(name, backend=Config.CELERY_RESULT_BACKEND, broker=Config.CELERY_BROKER_URL)

def init_celery(celery, app):
    celery.conf.update(app.config)

    class ContextTask(celery.Task):
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery.Task = ContextTask
    return celery

celery = make_celery()